﻿using System;
using System.Linq.Expressions;
using System.Web.UI;
using SBACN.WebSite.Code;
using SBACN.WebSite.Models;

namespace SBACN.WebSite.En.ContentDL
{
	public partial class ComList : BasePage
	{
		protected string Img { get; set; }
		protected void Page_Load(object sender, EventArgs e)
		{
			ImgData();
			if (!Page.IsPostBack)
				BindData(1);
		}

		protected void BindData(int pageIndex)
		{
			int records = 0;
			Expression<Func<TB_News, bool>> f = (p => p.Type == this.SystemCode && p.IsEn);
			Expression<Func<TB_News, DateTime>> order = (c => c.CreateDate);
			var resultC = DAL.DALHelper.Instance.GetList<TB_News, DateTime>(f, order, false, this.Pager1.PageSize, pageIndex, out records);

			if (resultC.Count > 0)
			{
				this.CouncilList.DataSource = resultC;
				this.CouncilList.DataBind();
				this.Pager1.RecordCount = records;
				this.Pager1.InitControl();
			}
		}

		protected void BindSelectedPageIndexChanged(int pageIndex, int nextPage)
		{
			BindData(nextPage);
		}

		protected void ImgData()
		{
			string type;
			if (string.IsNullOrWhiteSpace(this.SystemCode))
			{
				type = "";
			}
			else
			{
				type = this.SystemCode;
			}
			Expression<Func<TB_SystemConfig, bool>> f = (p => p.Code == "EnImg" && p.Type == type);
			var resultQ = DAL.DALHelper.Instance.GetFirstOrDefaultObject<TB_SystemConfig>(f);
			if (resultQ != null)
			{
				this.Img = resultQ.Value.ToString();
			}
		}
	}
}